package com.nue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nue.pojo.CheckApply;
import com.nue.mapper.CheckApplyMapper;
import com.nue.pojo.CheckItem;
import com.nue.service.ICheckApplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nue.service.ICheckItemService;
import com.nue.util.CommonResult;
import com.nue.util.HisConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wk
 * @since 2020-08-27
 */
@Service
public class CheckApplyServiceImpl extends ServiceImpl<CheckApplyMapper, CheckApply> implements ICheckApplyService {
    @Resource
    ICheckItemService checkItemService;

    @Override
    public CommonResult list(Integer registId) {
        QueryWrapper<CheckApply> qu =new QueryWrapper<>();
        qu.eq("register_id",registId);
        List list = this.list(qu);
        return CommonResult.success(list);
    }

    @Override
    public CommonResult save(Integer registerId, Integer[] ids) {
        for(int a: ids){
            CheckApply checkApply=new CheckApply();
            CheckItem checkItem=checkItemService.getById(a);
            checkApply.setRegisterId(registerId);
            checkApply.setItemId(a);
            checkApply.setItemName(checkItem.getName());
            checkApply.setFee(checkItem.getFee());
            checkApply.setStatus(HisConstants.CHECK_APPLY_STATUS_1);
            this.save(checkApply);
        }
        return CommonResult.success("保存成功");
    }
}
